package com.greenline.push.service.core.send.base;

import javax.annotation.Resource;

import org.apache.log4j.Logger;

import com.greenline.apns.dataobject.PushResult;
import com.greenline.echat.ss.share.dto.PushResponse;
import com.greenline.push.service.core.item.AppPacket;
import com.greenline.push.service.core.send.dto.ApnsPushMsgPacket;
import com.greenline.push.service.core.send.dto.EchatPushDomainPacket;
import com.greenline.push.service.core.send.dto.EchatPushPacket;
import com.greenline.push.service.core.utils.Constants;

public class SenderCallBackService {
    Logger log = Constants.LOG_PROCESS;
    @Resource
    private AppPacketHandler packetHandler;

    /**
     * apns 异步接收
     * 
     * @param result
     * @param msg
     */
    public void apnsCallbackp2p(PushResult result, ApnsPushMsgPacket msg) {
        AppPacket packet = msg.getAppPacket();
        boolean flag = false;
        log.debug(String.format("{调用apns发送接口apnsCallbackp2p}:结果:[%s--%s]***domainId:%s.tempId:%s.extparam:%s.发送内容:%s",
                result.getErrorCode(), result.getDesc(), packet.getDomainId(), packet.getTemplateId(), packet.getExtParam(),
                packet.getContext()));

        String errorCode = result.getErrorCode();
        if (errorCode.equals("0")) {
            flag = true;
        } else if (errorCode.equals("1")) {
            flag = false;
        }
        //
        packetHandler.afterSendOperation(packet, flag);
        // log return msg
        log.debug(String.format("{apnsCallbackp2p发送完成}:结果:%s***domainId:%s.tempId:%s.extparam:%s", result.getDesc(), packet.getDomainId(),
                packet.getTemplateId(), packet.getExtParam()));
    }

    /**
     * apns 异步接收 list
     * 
     * @param result
     * @param msg
     */
//    public void apnsCallbackList(PushResult result, ApnsPushGroupMsgPacket msg) {
//        AppPacket packet = msg.getAppPacket();
//        boolean flag = false;
//        log.debug(String.format("{调用apns发送接口apnsCallbackList}:结果:[%s--%s]***domainId:%s.tempId:%s.extparam:%s.发送内容:%s",
//                result.getErrorCode(), result.getDesc(), packet.getDomainId(), packet.getTemplateId(), packet.getExtParam(),
//                packet.getContext()));
//
//        String errorCode = result.getErrorCode();
//        if (errorCode.equals("0")) {
//            flag = true;
//        } else if (errorCode.equals("1")) {
//            flag = false;
//        }
//        //
//        packetHandler.afterSendOperation(packet, flag);
//        // log return msg
//        log.debug(String.format("{apnsCallbackList发送完成}:结果:%s***domainId:%s.tempId:%s.extparam:%s", result.getDesc(), packet.getDomainId(),
//                packet.getTemplateId(), packet.getExtParam()));
//    }

    /**
     * echat 异步接收
     * 
     * @param response
     * @param msg
     */
    public void echatCallback(PushResponse result, EchatPushPacket msg) {
        AppPacket packet = msg.getAppPacket();
        packetHandler.afterSendOperation(packet, result.isSuccess());
        // log return msg
        log.debug(String.format("{echatCallback**echat点对点推送结果}context:%s,userIdlist:%s,response:%s", packet.getContext(),
                msg.getFullJidList(), result.isSuccess() + "**code:" + result.getCode()));
    }

    /**
     * echat 异步接收,发送到域
     * 
     * @param response
     * @param msg
     */
    public void echatDomainCallback(PushResponse result, EchatPushDomainPacket msg) {
        AppPacket packet = msg.getAppPacket();
        packetHandler.afterSendOperation(packet, result.isSuccess());
        // log return msg
        log.debug(String.format("{echatDomainCallback**echat点对点推送结果}context:%s,userIdlist:%s,response:%s", packet.getContext(),
                msg.getUserIdList(), result.isSuccess() + "**code:" + result.getCode()));
    }

    public void smsCallback() {
        // 没有做成异步
    }

    public void emailCallback() {
        // 没有做成异步
    }

    public void weixinCallback() {
        // 没有做成异步
    }
}
